package org.zcq100.Net;
import java.net.*;
import static org.zcq100.Print.*;

public class UDPTest {
	public static void send(){
		try{
		DatagramSocket ds=new DatagramSocket(6666);
		String str="I am s best programner!";
		DatagramPacket dp=new DatagramPacket(str.getBytes(),str.length(),InetAddress.getByName("localhost"),6666);
		ds.send(dp);
		ds.close();
		}catch(Exception e){
			e.printStackTrace();
		}
}
	public static void Recive(){
		try{
		byte[] data=new byte[100];
		DatagramPacket dp=new DatagramPacket(data,data.length);
		DatagramSocket ds=new DatagramSocket(6666);
		ds.receive(dp);
		ds.close();
		
		println(data);
		}catch(Exception e){
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		if(args.length>0)
			Recive();
		else
			send();
	}
}
